package user_v1

import (
	"context"
	fm "gf-xb-api/cwt/filter/model"
	"gf-xb-api/cwt/filter/parser"
	"gf-xb-api/internal/dao"
	"gf-xb-api/internal/model/dto"
	"gf-xb-api/internal/model/vo"
)

func (s *sUser) GetUserList(ctx context.Context, in *fm.PageRequest[dto.UserListInput]) (data *fm.PageData[*vo.UserList], err error) {

	var m = dao.SysUser.Ctx(ctx)

	m, err = parser.ConvertObjectToMPAndSort(in, m)
	if err != nil {
		return nil, err
	}

	res, total, err := m.AllAndCount(false)
	if err != nil {
		return nil, err
	}

	var rows []*vo.UserList
	if err = res.Structs(&rows); err != nil {
		return nil, err
	}

	data = &fm.PageData[*vo.UserList]{}
	data.Total = (int64)(total)
	data.Rows = rows

	return data, nil
}
